﻿@{
    ViewData["Title"] = "Home Page";
}

<style>
    .overflow-scroll {
        height: 500px;
    }
</style>

<div class="text-center">
    <h1 class="display-4">Steeltoe Configuration Providers Sample</h1>
    <table class="table table-bordered">
        <tr>
            <td>
                <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="ExternalConfigurationData">View Externalized Configuration</a>
            </td>
            <td>
                <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="ConfigServerSettings">View Config Server Client Settings</a>
            </td>
        </tr>
        <tr>
            <td>
                <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="RandomValues">View Random Values from Configuration</a>
            </td>
            <td>
                <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="PlaceholderValues">View Placeholder Resolver Results</a>
            </td>
        </tr>
        <tr>
            <td>
                <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="CloudFoundry">View Configuration from Cloud Foundry</a>
            </td>
            <td></td>
        </tr>
        <tr>
            <td colspan="2">
                <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16">
                    <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1"/>
                </svg>
                Use actuators to viewing or refreshing configuration
                <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16">
                    <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1"/>
                </svg>
            </td>
        </tr>
        <tr>
            <td>
                <a class="nav-link text-dark" href="/actuator/env">View All Configuration</a>
            </td>
            <td>
                <a class="nav-link text-dark" href="#" onclick="refreshActuator()">Refresh Configuration</a>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <div id="refreshResult"></div>
            </td>
        </tr>
    </table>
</div>

<script>
    function refreshActuator() {
        if (!$("#refreshResult").hasClass("spinner-border")) {
            $("#refreshResult").addClass("spinner-border");
            $("#refreshResult").removeClass("overflow-scroll");
            $("#refreshResult").html("");
            $.post('/actuator/refresh', function (data) {
                $("#refreshResult").append("<h4>Response from refresh actuator</h4>");
                data.forEach((item) => {
                    $("#refreshResult").append(item + "<br />");
                });
                $("#refreshResult").removeClass("spinner-border");
                $("#refreshResult").addClass("overflow-scroll");
            })
        }
    }
</script>
